package com.kitty.web.controller;

import com.kitty.web.controller.BaseController;
import com.kitty.web.common.AjaxResult;
import com.kitty.web.core.page.TableDataInfo;
import com.kitty.web.domain.PChoujianggift;
import com.kitty.web.system.choujianggift.service.IPChoujianggiftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 抽奖配置Controller
 * 
 * @author soul
 * @date 2022-03-10
 */
@Controller
@RequestMapping("/system/choujianggift")
public class PChoujianggiftController extends BaseController
{
    private String prefix = "system/choujianggift";

    @Autowired
    private IPChoujianggiftService pChoujianggiftService;


    @GetMapping()
    public String choujianggift()
    {
        return prefix + "/choujianggift";
    }

    /**
     * 查询抽奖配置列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PChoujianggift pChoujianggift)
    {
        startPage();
        List<PChoujianggift> list = pChoujianggiftService.selectPChoujianggiftList(pChoujianggift);
        return getDataTable(list);
    }



    /**
     * 新增抽奖配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存抽奖配置
     */

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PChoujianggift pChoujianggift)
    {
        return toAjax(pChoujianggiftService.insertPChoujianggift(pChoujianggift));
    }

    /**
     * 修改抽奖配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PChoujianggift pChoujianggift = pChoujianggiftService.selectPChoujianggiftById(id);
        mmap.put("pChoujianggift", pChoujianggift);
        return prefix + "/edit";
    }

    /**
     * 修改保存抽奖配置
     */

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PChoujianggift pChoujianggift)
    {
        return toAjax(pChoujianggiftService.updatePChoujianggift(pChoujianggift));
    }

    /**
     * 删除抽奖配置
     */

    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(pChoujianggiftService.deletePChoujianggiftByIds(ids));
    }
}
